<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class IndexController extends Controller
{
    public function index()
    { 
    	$list = session('wechat.oauth_user')->original;
    	if($list){
    		$openid=\DB::table('admin_users')->where('openid',$list['openid'])->first();
            // 通过全局辅助函数
            $userrole=\DB::table("admin_role_users")->where('user_id',$openid->id)->pluck("role_id");
            $name=$openid->username;
            $role=\DB::table("admin_roles")->whereIn("id",$userrole)->pluck("name");
            session(['wechat.userid' => $openid->id]);
            session(['wechat.role' => $role]);
    		if($openid){
    			return view("index",['name'=>$name]);
    		}else{
    			return "<h1>你没有权限进行此操作！</h1>";
    		}
    	}else{ 
            return "无效的账户";
        }
    } 
}
